package Hot100.Greedy_algorithm;

import java.util.ArrayList;
import java.util.List;

public class partitionLabels {
    public static void main(String[] args) {
        String s = "e";
        List <Integer>list = new partitionLabels().partitionLabels(s);
        for (int num: list){
            System.out.print(num + "  ");
        }
    }
    public List<Integer> partitionLabels(String s) {
        List<Integer> list = new ArrayList<>();
        int max = 0;
        while (max < s.length()){
            int length = part(s.substring(max));
            list.add(length);
            max += length;
        }
        return list;
    }
    public int part(String s){
        List<Character> list = new ArrayList<>();
        int last = 0;
        for (int i = 0; i <= last ; i++) {
            if(!list.contains(s.charAt(i))){
                list.add(s.charAt(i));
                int k = s.length() - 1;
                while (s.charAt(k) != s.charAt(i)){
                    k--;
                }
                if(k == s.length() - 1){
                    return k + 1;
                }
                if(k > last)
                    last = k;
            }
        }
        return last + 1;
    }
}
